package com.yc.bbs;

import com.yc.bbs.controller.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@SpringBootApplication
@MapperScan("com.yc.bbs.dao")
public class BbsBootApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(BbsBootApplication.class, args);
    }

    @Value("${uploadDir}")
    String uploadDir;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/head/**")
                .addResourceLocations(uploadDir);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/post.html","/back/**");
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter(){



        return new ServerEndpointExporter();
    }
}
